﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Threading;
using System.Net;
using System.Net.Sockets;

namespace NetworkingLibrary.Clients
{
    public interface IClient
    {
        int MaxFlowRate
        {
            get;
            set;
        }
        DateTime LastSendTime
        {
            get;
            set;
        }
        
        event Events.ClientConnectDelegate OnConnect;
        event Events.ClientDisconnectDelegate OnDisconnect;
        event Events.MessageReceivedDelegate OnMessageReceived;
        event Events.ErrorDelegate OnError;

        Guid ID
        {
            get;
            set;
        }

        int BufferSize
        {
            get;
            set;
        }

        bool Terminating
        {
            get;
            set;
        }

        bool Connected
        {
            get;
        }

        bool Connect(int Port, IPAddress TheAddress, bool ShouldStart = true);
        bool Disconnect(bool IgnoreSocketState = false);
        
        bool Start();
        bool Stop();

        bool Send(byte[] Data);
        bool Send(Messages.MessageObject TheMessage);
    }
    public class EmptyClient : IClient
    {
        private int maxFlowRate = 5;
        public int MaxFlowRate
        {
            get
            {
                return maxFlowRate;
            }
            set
            {
                maxFlowRate = value;
            }
        }
        DateTime lastSendTime = new DateTime();
        public DateTime LastSendTime
        {
            get
            {
                return lastSendTime;
            }
            set
            {
                lastSendTime = value;
            }
        }

        public event Events.ClientConnectDelegate OnConnect = delegate { };
        public event Events.ClientDisconnectDelegate OnDisconnect = delegate { };
        public event Events.MessageReceivedDelegate OnMessageReceived = delegate { };
        public event Events.ErrorDelegate OnError = delegate { };

        public Guid ID
        {
            get;
            set;
        }
        public IPAddress Address
        {
            get;
            set;
        }
        public int Port
        {
            get;
            set;
        }

        public int BufferSize
        {
            get;
            set;
        }

        public bool Terminating
        {
            get;
            set;
        }

        public bool Connected
        {
            get
            {
                return false;
            }
        }

        public bool Connect(int Port, IPAddress TheAddress, bool ShouldStart = true)
        {
            throw new NotImplementedException("Should and will never be implemnted - this is an EmptyClient");
        }
        public bool Disconnect(bool IgnoreSocketState = false)
        {
            throw new NotImplementedException("Should and will never be implemnted - this is an EmptyClient");
        }

        public bool Start()
        {
            throw new NotImplementedException("Should and will never be implemnted - this is an EmptyClient");
        }
        public bool Stop()
        {
            throw new NotImplementedException("Should and will never be implemnted - this is an EmptyClient");
        }

        public bool Send(byte[] Data)
        {
            throw new NotImplementedException("Should and will never be implemnted - this is an EmptyClient");
        }
        public bool Send(Messages.MessageObject TheMessage)
        {
            throw new NotImplementedException("Should and will never be implemnted - this is an EmptyClient");
        }
    }
}
